package com.payment.transactions.enums;

/**
 * 收支类型枚举
 */
public enum IncomeExpenseType {
    INCOME(1, "收入"),
    EXPENSE(2, "支出"),
    IGNORE(3, "不计收支"),
    IGNORE2(3, "/");

    private final Integer code;
    private final String description;

    IncomeExpenseType(Integer code, String description) {
        this.code = code;
        this.description = description;
    }

    public Integer getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    public static IncomeExpenseType fromCode(Integer code) {
        for (IncomeExpenseType type : IncomeExpenseType.values()) {
            if (type.code.equals(code)) {
                return type;
            }
        }
        return null;
    }

    /**
     * 将收支类型字符串转换为整数
     */
    public static Integer fromDescription(String type) {
        if (type == null) {
            return null;
        }
        for (IncomeExpenseType incomeExpenseType : IncomeExpenseType.values()) {
            if (incomeExpenseType.getDescription().equals(type)) {
                return incomeExpenseType.getCode();
            }
        }
        return null;
    }
}
